﻿using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using DT.Core.Models;
using Furion;
using Furion.DynamicApiController;
using Furion.LinqBuilder;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using XCPFrame.Core.Managers;

namespace XCPFrame.Application.Api
{
    /// <summary>
    /// API DEMO 
    /// </summary>
    [AppAuthorize, ApiDescriptionSettings("DEMO列表")]
    public class DemoApiService : IDynamicApiController
    {
        private readonly ISqlSugarRepository repository;
        private readonly SqlSugarClient db;

        public DemoApiService(ISqlSugarRepository sqlSugarRepository)
        {
            repository = sqlSugarRepository;
            db = repository.Context;

            //配置用户角色
            //db.ConfigQuery.SetTable<SysRole>(it => it.Id, it => it.Name);
                
           
        }

        /// <summary>
        /// 测试API Demo
        /// </summary>
        /// <returns></returns>
        /// //自定义过滤器"自定义资源ID"
        [SecurityDefine(CoreSecurityAttribute.ViewRoles)]
        public string GetDemo()
        {
            //获取登录时生成的jwt token中的数据
            var userId = App.User?.FindFirstValue("AppType");
            return "hello world ：" + userId;
        }

        /// <summary>
        /// 级联配置查询方法demo
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public BaUser PostUserAllInfo(BaUser user)
        {
            BaUser rs = new BaUser();

            rs = db.Queryable<BaUser>().Where(u => u.Id == 1).Select(it => new BaUser
            {
                Id = it.Id.SelectAll(),
                CreateManName = it.CreateMan.GetConfigValue<BaUser>()
            }).First();


            return rs;
        }

        /// <summary>
        /// cs
        /// </summary>
        /// <returns></returns>
        public int CS()
        {
            return 0;
        }


    }
}
